<template>
  <div id="app">
    <el-container>
      <el-container>
        <!-- 头部，可放置页面标题等 -->
        <el-header class="my-header">
          <h1>消息列表</h1>
        </el-header>
        <el-main>
          <!-- 通知详情内容 -->
          <div v-for="(item,index) in notification" :key="index" class="notification-detail">
            <h2>重要消息：{{ item.noticeTitle }}</h2>
            <p class="publish-time">发布时间：{{ item.createTime }}</p>
            <div class="content">
              {{item.noticeContent}}
            </div>
          </div>
        </el-main>
      </el-container>
    </el-container>
  </div>
</template>

<script setup>
import {onMounted, ref} from 'vue';
import {listNotice} from "@/api/article.js"
import router from "@/router/index.js"
import useUserStore from "@/stores/user.js";
const userStore = useUserStore()
const userId = userStore.id

// 模拟通知数据
const notification = ref([]);

onMounted(async ()=>{
  console.log(typeof (userId))
  if (userId===''){
    await router.push({
      name: "login"
    })
  }
  console.log("userStore.id",userId)
  const {data:{rows}} = await listNotice(userId);
  notification.value = rows
})
</script>

<style scoped>
#app {
  font-family: Avenir, Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-align: center;
  color: #2c3e50;
  margin-top: 10px;
  min-height: 100vh;
}
.notification-detail {
  text-align: left;
  background-color: #fff;
  padding: 20px;
  border-radius: 8px;
  box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
  margin: 40px;
}

.publish-time {
  color: #909399;
  margin-bottom: 20px;
}

.content {
  line-height: 1.6;
}
</style>